/**
 * 
 */
package com.swg.cocobox.filetransfer.internal;

import java.nio.charset.Charset;

import com.swg.cocobox.filetransfer.command.ReplyCommand;

/**
 * @author satriaprayoga
 *
 */
public final class ASCIIReplyCommandParser implements ReplyCommandParser {

	@Override
	public ReplyCommand parseReply(byte[] data) {
		String replyS=new String(data,Charset.forName("US-ASCII"));
		String[] sreply=replyS.split("\\s");
		int code=Integer.valueOf(sreply[0]);
		String message=null;
		StringBuilder builder=new StringBuilder();
		for(int i=1;i<sreply.length;i++){
			builder.append(sreply[i]+" ");
		}
		message=builder.toString();
		ReplyCommand command=new ReplyCommandImpl(Charset.forName("US-ASCII"), code, message.trim());
		return command;
	}

}
